package com.max.back.examination.api;

import cn.hutool.core.collection.CollUtil;
import com.max.back.common.http.ResponseResult;
import com.max.back.entity.Check;
import com.max.back.entity.CheckItem;
import com.max.back.examination.form.CheckFrom;
import com.max.back.examination.service.CheckService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author hanfeng
 * @date 2022/7/21
 */
@CrossOrigin
@RestController
@RequestMapping("/check")
public class CheckController {

    @Autowired
    private CheckService checkService;


    //1.查询检查列表
    @GetMapping("/list")
    public ResponseResult list(String title){
        List<CheckFrom> list=checkService.getChecklist(title);
        return CollUtil.isNotEmpty(list)?
                ResponseResult.getSuccessResult(list,"获取检查列表成功！",null)
                                    :ResponseResult.getMessageResult(list,"检查项列表为空！");
    };

    //1.录入检查结果
    @PutMapping
    public ResponseResult edit(@RequestBody CheckFrom checkFrom){
        checkService.edit(checkFrom.getCheckItemId(),checkFrom.getResult());
        return ResponseResult.getSuccessResult(null,"录入结果成功！",null);
    };
}
